<template>
	<view class="goods_list">
		<goods-list :goods='goods'></goods-list>
		<view class="isOver" v-if="flag">
			----已经到底啦----
		</view>
	</view>
</template>

<script>
	import goodsList from "../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				goods: [],
				flag: false,
			}
		},
		components: {
			"goods-list": goodsList
		},
		onLoad() {
			this.getGoodsList()
		},
		// 触底函数
		onReachBottom() {
			// console.log(this.goods.length)
			if (this.goods.length < 9) return this.flag = true
		},
		onPullDownRefresh() {
			console.log('下拉刷新成功')
			this.goods = []
			this.flag = false
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		methods: {
			async getGoodsList(callback) {
				const res = await this.$myRequest({
					url: '/api/getgoods'
				})
				this.goods = res.data.message
				//this.goods = [...this.goods,...res.data.message] 用于多页数据时的显示
				callback && callback()
			}
		}
	}
</script>

<style>
	.goods_list {
		background: #eee;
	}

	.isOver {
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 28rpx;
	}
</style>
